<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta --><!DOCTYPE html>
    <html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>传智健康</title>
        <meta name="description" content="传智健康">
        <meta name="keywords" content="传智健康">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
        <link rel="stylesheet" href="../css/style.css">
        <!-- 引入组件库 -->
        <script src="../js/vue.js"></script>
        <script src="../plugins/elementui/index.js"></script>
        <script type="text/javascript" src="../js/jquery.min.js"></script>
        <script src="../js/axios-0.18.0.js"></script>
        <script src="../plugins/echarts/echarts.js"></script>
    </head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>统计分析
            <small>会员数量</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>月份粒度统计分析</el-breadcrumb-item>
            <el-breadcrumb-item>会员数量</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div>
        <div class="add-form">
            <el-form ref="dataAddForm" :model="time" label-position="right"
                     label-width="100px">
                <el-row>
                    <el-col :span="5">
                        <el-form-item label="开始时间">
                            <el-date-picker type="date" placeholder="选择日期" v-model="time.begin"
                                            style="width: 100%;"></el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="5">
                        <el-form-item label="截止时间">
                            <el-date-picker type="date" placeholder="选择日期" v-model="time.end"
                                            style="width: 100%;"></el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-form-item>
                        <el-button type="primary" @click="submitForm('time')">提交</el-button>
                        <el-button @click="resetForm('time')">重置</el-button>
                    </el-form-item>
                </el-row>
            </el-form>
        </div>
    </div>
    <div class="app-container">
        <div class="box">
            <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
            <div id="chart1" style="height:500px;"></div>
        </div>
    </div>
</div>
</body>
<script>
    var myChart1;
    var vue = new Vue({
        el: '#app',
        data: {
            time: {},//表单数据
            month: [],
            counts: []
        },
        methods: {
            //添加
            submitForm() {

                this.$refs['dataAddForm'].validate(valid => {
                    if (valid) {
                        //开始时间
                        var begin;
                        if (this.time.begin == undefined) {
                            begin = new Date();
                        } else {
                            begin = new Date(this.time.begin);
                        }
                        this.time.begin = this.formatDate(begin.getFullYear(), begin.getMonth() + 1, begin.getDate());
                        //截止时间
                        var end;
                        if (this.time.end == undefined) {
                            end = new Date();
                        } else {
                            end = new Date(this.time.end);
                        }
                        this.time.end = this.formatDate(end.getFullYear(), end.getMonth() + 1, end.getDate());

                        //    表单通过验证 ，发送请求
                        axios.post("/report/getMemberInTime.do", {
                            beginDate: this.time.begin,
                            endDate: this.time.end
                        }).then((response) => {

                            if (response.data.flag){
                                this.month=[];
                                this.counts=[];
                               for(var i=0;i<response.data.data.length;i++){
                                  this.month.push(response.data.data[i].month);
                                   this.counts.push(response.data.data[i].count);
                               }
                                myChart1.setOption(
                                    {
                                        title: {
                                            text: '会员数量'
                                        },
                                        tooltip: {},
                                        legend: {
                                            data: ['会员数量']
                                        },
                                        xAxis: {
                                            show: true,
                                            data: this.month

                                        },
                                        yAxis: {
                                            type: 'value',
                                            interval: 10
                                        },
                                        series: [{
                                            name: '会员数量',
                                            type: 'bar',
                                            barMaxWidth: 50,
                                            barMinWidth: 10,
                                            data: this.counts


                                        }]
                                    });
                               console.log(this.month);
                            }
                        });
                    } else {
                        // 表单验证失败
                        this.$message.error("表单数据验证失败");
                        return false;
                    }
                });
            },
            // 重置表单
            resetForm(formName) {
                this.time = {};
                this.$refs[formName].resetFields();
            },
            // 返回 类似 2016-01-02 格式的字符串
            formatDate: function (year, month, day) {
                var y = year;
                var m = month;
                if (m < 10) m = "0" + m;
                var d = day;
                if (d < 10) d = "0" + d;
                return y + "-" + m + "-" + d
            }
        },
        mounted() {
            myChart1 = echarts.init(document.getElementById('chart1'));

        },

    });
</script>


<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../js/axios-0.18.0.js"></script>
</html>
